﻿using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XjjXmm.FrameWork.Cache;
using XjjXmm.FrameWork.ToolKit;
using XjjXmm.Infrastructure.Constant;

namespace XjjXmm.Infrastructure.User
{
    public class User : IUser
    {
        private readonly IHttpContextAccessor _accessor;

        private readonly ICache _cache;

        public User(ICache cache, IHttpContextAccessor accessor)
        {
            _cache = cache;

            //cache.Get<l>($"user_{Id}");
            //Id = accessor.HttpContext.User.Identity?.Name?.ToLong() ?? 0;
            //UserName = cache.Get<String>($"{CacheKey.UserName}:{Id}");
            //NickName = cache.Get<String>($"{CacheKey.NickName}:{NickName}");
            _accessor = accessor;
        }

        public long Id
        {
            get
            {
                return _accessor.HttpContext.User.Identity?.Name?.ToLong() ?? 0;
            }
        }
       
        public string UserName => _cache.Get<String>($"{CacheKey.UserName}:{Id}");
        public string NickName => _cache.Get<String>($"{CacheKey.NickName}:{Id}");
    }
}
